home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1998 September
/
EnigmA AMIGA RUN 30 (1998)(G.R. Edizioni)(IT)[!][issue 1998-09].iso
/
earkit
/
news
/
thor
/
rexx
/
adduser.thor
< prev
next >
Wrap
Text File
|
1998-07-09
|
11KB
|
375 lines
/*
* $VER: AddUser.thor 1.50 (4.9.97)
*
* by Magne Østlyngen and Eirik Synnes
*
* Adds the sender or any recipient of the current or multiselected
* messages to the user database.
*
* New in 1.3:
* Messages can be multiselected
* Abiity to add addresses from all From:, To: and Cc: header lines
* Now handles double quotes and asterixes
* Some minor bugfixes and improvements
*
* New in 1.4:
* Some debug info was left in 1.3 making the script useless :/
* Replaced the four confirmation requesters with one listview
* Existing entries in the user database can optionally be replaced
*
* New in 1.41:
* Put the "Cancel" choice in the editing requesters back in
* The script would always quit after adding one user
*
* New in 1.42:
* Fixed some remaining problems with double quotes and asterixes
*
* New in 1.50:
* Users can be multiselected
* Version numbering will from now on be following the C= guidelines
*
*/
options results
options failat 31
msglist.count = 0
p = ' ' || address() || ' ' || show('P',,)
thorport = pos(' THOR.',p)
if thorport > 0 then thorport = word(substr(p,thorport+1),1)
else
do
say 'No THOR port found!'
exit 10
end
if ~show('p', 'BBSREAD') then do
address command
"run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
"WaitForPort BBSREAD"
end
address(thorport)
'CURRENTSYSTEM STEM 'cursys
if (rc ~= 0) then do
if (rc = 1) then do
'REQUESTNOTIFY "No system open." "Ok"'
exit(0)
end
else do
'REQUESTNOTIFY "CURRENTSYSTEM failed: 'THOR.LASTERROR'" "Ok"'
exit(0)
end
end
if (cursys.CONFNAME = '') then do
'REQUESTNOTIFY "No conference open." "Ok"'
exit(0)
end
'GETMSGLISTSELECTED STEM 'msglist
select
when (rc = 3 | rc = 5) then do
'CURRENTMSG STEM 'msg
if rc~=0 then do
REQUESTNOTIFY '"CURRENTMSG failed: '||THOR.LASTERROR||'"' '"Ok"'
exit
end
msglist.1 = msg.msgnr; msglist.count = 1
drop msg.
end
when (rc = 0) then nop
otherwise do
'REQUESTNOTIFY "GETMSGLISTSELECTED failed: 'THOR.LASTERROR'" "Ok"'
exit(0)
end
end
do i = 1 to msglist.count
drop new. userlist. head. text.
cancelled = 0
address(bbsread)
'READBRMESSAGE "'||cursys.bbsname||'" "'||cursys.confname||'" 'msglist.i' HEADSTEM 'head' TEXTSTEM 'text
if (rc ~=0) then do
address(thorport)
'REQUESTNOTIFY "READBRMESSAGE failed on message ' || msglist.i || ':\n' || BBSREAD.LASTERROR || '" "Ok"'
exit
end
call parseaddr(1, 1)
do j = 1 to addrs.count
userlist.j = left(addrs.j.name, 30) || ' '
userlist.j = userlist.j || '<' || addrs.j.addr || '>'
end
userlist.count = addrs.count
do while ~(cancelled)
address(thorport)
'REQUESTLIST INSTEM 'userlist' OUTSTEM 'seluser' TITLE "Select user(s) or Cancel for next message" SIZEGADGET MULTISELECT'
select
when (rc > 5) then do
'REQUESTNOTIFY "REQUESTLIST failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
when (rc = 5) then cancelled = 1
otherwise do
do u = 1 to seluser.COUNT
selected = seluser.u
drop new. useredit.
do j = 1 to addrs.count while selected = seluser.u
if selected = userlist.j then selected = j
end
new.name = addrs.selected.name
new.address = addrs.selected.addr
new.comment.1 = ''
new.alias = ''
finished = 0
do while ~(finished)
useredit.1 = 'Add this new user'
useredit.2 = ''
useredit.3 = 'Name: ' || new.name
useredit.4 = 'Addr: ' || new.address
useredit.5 = 'Alias: ' || new.alias
useredit.6 = 'Comm: ' || new.comment.1
useredit.count = 6
address(thorport)
'REQUESTLIST INSTEM 'useredit' TITLE "Edit user" SIZEGADGET'
if (rc > 5) then do
'REQUESTNOTIFY "REQUESTLIST failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
choice = result
choice = result
do j = 1 to useredit.count while choice = result
if choice = useredit.j then choice = j
end
select
when (rc > 5) then do
'REQUESTNOTIFY "REQUESTLIST failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
when (rc = 5) then finished = 1
when (rc = 0) & (choice = 3) then do
'REQUESTSTRING TITLE="Enter Name:" BT="Ok|Cancel" ID="'||addasterix(new.name)||'" MAXCHARS=100'
if rc = 0 then new.name = result
else if (rc > 5) then do
'REQUESTNOTIFY "REQUESTSTRING failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
end
when (rc = 0) & (choice = 4) then do
REQUESTSTRING 'TITLE="Enter Address:" BT="Ok|Cancel" ID="'||addasterix(new.address)||'" MAXCHARS=100'
if rc = 0 then new.address = result
else if (rc > 5) then do
'REQUESTNOTIFY "REQUESTSTRING failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
end
when (rc = 0) & (choice = 5) then do
'REQUESTSTRING TITLE="Enter Alias:" ID="' || addasterix(new.alias) || '" BT="Ok|Cancel" MAXCHARS=100'
if rc = 0 then new.alias = result
else if (rc > 5) then do
'REQUESTNOTIFY "REQUESTSTRING failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
end
when (rc = 0) & (choice = 6) then do
REQUESTSTRING 'TITLE="Enter Comment:" ID="' || addasterix(new.comment.1) || '" BT="Ok|Cancel" MAXCHARS=100'
if rc = 0 then new.comment.1 = result
else if (rc > 5) then do
'REQUESTNOTIFY "REQUESTSTRING failed: ' || THOR.LASTERROR || '" "Ok"'
exit(0)
end
end
when (rc = 0) & (choice = 1) then do
if new.comment.1 = "" then new.comment.count = 0; else new.comment.count = 1
deluser = 0; drop userseach.
address(bbsread)
'SEARCHBRUSER BBSNAME "'cursys.bbsname'" STEM 'usersearch' SEARCH "' || addasterix(new.address) || '" ADDRESS'
if (rc ~= 0) then do
address(thorport)
'REQUESTNOTIFY "SEARCHBRUSER failed: ' || BBSREAD.LASTERROR || '" "Ok"'
exit(0)
end
address(thorport)
if (result > 0) then do
'REQUESTNOTIFY "A user with this address already\nexists. Do you want to replace\nthis user?" "Yes|No"'
if (result > 0) then deluser = 1
end
firstsearch = usersearch.1.usernr
address(bbsread)
'SEARCHBRUSER BBSNAME "'cursys.bbsname'" STEM 'usersearch' SEARCH "' || addasterix(new.name) || '" NAME'
if (rc ~= 0) then do
address(thorport)
'REQUESTNOTIFY "SEARCHBRUSER failed: ' || BBSREAD.LASTERROR || '" "Ok"'
exit(0)
end
if (result > 0) & ~(deluser) & ~(usersearch.1.usernr = firstsearch) then do
address(thorport)
'REQUESTNOTIFY "A user with this name already\nexists. Do you want to replace\nthis user?" "Yes|No"'
if (result > 0) then deluser = 1
end
if (deluser) then do
address(bbsread)
'WRITEBRUSER "'cursys.bbsname'" UPDATEUSERNR 'usersearch.1.USERNR' DELETEUSER'
if (rc ~= 0) then do
address(thorport)
'REQUESTNOTIFY "WRITEBRBRUSER failed: ' || BBSREAD.LASTERROR || '" "Ok"'
exit(0)
end
end
address(bbsread)
'WRITEBRUSER "' || cursys.bbsname || '" STEM 'new
if (rc ~= 0) then do
address(thorport)
'REQUESTNOTIFY "WRITEBRUSER failed: ' || BBSREAD.LASTERROR || '" "Ok"'
exit(0)
end
finished = 1
end
otherwise nop
end /* select */
end /* ~(finished) */
end /* do i = 1 to seluser.COUNT */
end /* otherwise */
end /* select */
end /* ~(cancelled) */
end
syntax:
break_c:
halt:
exit
/****************************************************************************
*************** Put addresses and names in a string into a stem ***************
****************************************************************************/
parseaddr: procedure expose addrs. text. head.
parse arg checkfromaddr, checkcc
i = 1; acnt = 0; usedhead = 0; drop addrs.
if checkfromaddr = 1 then do
acnt = acnt + 1; addrs.acnt.name = head.FROMNAME
if (symbol('head.FROMADDR') = 'VAR') then addrs.acnt.addr = head.FROMADDR
else addrs.acnt.addr = ''
end
if (symbol('head.TOADDR') = 'VAR') & ~(index(head.TOADDR, ',') > 0) then do
acnt = acnt + 1; addrs.acnt.name = ''; addrs.acnt.cc = 0; usedhead = 1
addrs.acnt.addr = head.TOADDR
if (symbol('head.TONAME') = 'VAR') then addrs.acnt.name = head.TONAME
end
if (symbol('text.COMMENT.COUNT') = 'VAR') then if (text.COMMENT.COUNT > 0) then do while i <= text.COMMENT.COUNT
thiscc = 0
if (checkcc = 1) & (upper(subword(text.COMMENT.i, 1, 1)) = 'CC:') then thiscc = 1
if (thiscc) | (upper(subword(text.COMMENT.i, 1, 1)) = 'TO:') then do
addrs = subword(text.COMMENT.i, 2)
do forever
addrs = strip(addrs, 'B', ' ' || '09'x)
offset = 1
do forever
length = index(substr(addrs, offset), ','); if (length = 0) then length = length(addrs) - offset + 1
thisaddr = strip(substr(addrs, offset, length), 'B', ', ');
acnt = acnt + 1; addrs.acnt.addr = ''; addrs.acnt.name = ''
if (thiscc) then addrs.acnt.cc = 1; else addrs.acnt.cc = 0
if (words(thisaddr) = 1) then addrs.acnt.addr = strip(thisaddr, 'B', '<>()')
else if (index(thisaddr, '<') > 0) then do
addrstart = index(thisaddr, '<')
addrlength = index(substr(thisaddr, addrstart), '>')
addrs.acnt.addr = strip(substr(thisaddr, addrstart + 1, addrlength), 'B', '> ')
addrs.acnt.name = strip(delstr(thisaddr, addrstart, addrlength), 'B', ' "' || '27'x)
end
else do j = 1 to words(thisaddr)
thispart = strip(subword(thisaddr, j, 1), 'B', '<>" ' || '27'x)
if (index(thispart, '@') > 0) then addrs.acnt.addr = thispart
else addrs.acnt.name = addrs.acnt.name || thispart || ' '
end
if ~(thiscc) & (usedhead) & (addrs.acnt.addr = addrs.1.addr) & (addrs.acnt.name = addrs.1.name) then do
drop addrs.acnt.; acnt = acnt - 1
end
if (offset + length >= length(addrs)) then break
offset = offset + length
end
j = i + 1; if ~((c2d(left(text.COMMENT.j, 1)) = 9) | (c2d(left(text.COMMENT.j, 1)) = 32)) then break
i = i + 1; addrs = text.COMMENT.i
end
end
i = i + 1
end
addrs.COUNT = acnt
return(0)
/****************************************************************************
****** Insert asterix (*) before double quotes (") and existing asterixes *****
****************************************************************************/
addasterix: procedure
parse arg str
if str = '' then return(str)
lastfound = 0; found = index(str, '*')
do while found > lastfound
secondpart = substr(str, found + length('*'))
firstpart = substr(str, 1, length(str) - length(substr(str, found)))
str = firstpart || '**' || secondpart
lastfound = found + length('**')
found = index(str, '*', lastfound)
end
lastfound = 0; found = index(str, '"')
do while found > lastfound
secondpart = substr(str, found + length('"'))
firstpart = substr(str, 1, length(str) - length(substr(str, found)))
str = firstpart || '*"' || secondpart
lastfound = found + length('*"')
found = index(str, '"', lastfound)
end
return(str)